<blockquote class="layui-elem-quote">订单管理</blockquote>
<div class="layuimini-container">
  <div class="layuimini-main">

    <fieldset class="table-search-fieldset">
      <legend>搜索信息</legend>
      <div style="margin: 10px 10px 10px 10px">
        <form class="layui-form layui-form-pane" action="">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">关键字</label>
              <div class="layui-input-inline">
                <input type="text" id="keyword" name="categoryname" autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
        </form>
      </div>
    </fieldset>


    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="currentTableBar">
      <button  type="button"  class="layui-btn layui-btn-xs" lay-event="detail"> 订单详情 </button>
      <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
    </script>


  </div>
</div>
<!--<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>-->
<script >
  layui.use(['form', 'table','upload'], function () {
    var $ = layui.jquery,
            form = layui.form,
            upload = layui.upload,
            table = layui.table;

    table.render({
      elem: '#currentTableId',
      url: '/api/order/page',
      toolbar: '#toolbarDemo',
      limits: [5, 10, 15, 20, 100],
      limit: 10,
      page: true,
      skin: 'line',
      defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示',
        layEvent: 'LAYTABLE_TIPS',
        icon: 'layui-icon-tips'
      }],
      request:{
        pageName: 'pageNum',
        limitName: 'pageSize'
      },
      response:{
        statusCode:10000
      },
      parseData: function(res){ //res 即为原始返回的数据
        return {
          "code": res.code, //解析接口状态
          "msg": res.msg, //解析提示文本
          "count": res.data.total, //解析数据长度
          "data": res.data.list //解析数据列表
        };
      },
      cols: [[
        {field: 'id',  title: 'ID'},
        {field: 'createTime', title: '创建时间'},
        {field: 'userId', title: '用户', templet:function (d) {
            if(d.user){
              return d.user.username;
            }else {
              return "";
            }

          } },
        {field: 'addrId', title: '地址', templet:function (d) {
            if(d.addr){
              return d.addr.province+d.addr.city+d.addr.town+d.addr.detail;
            }else {
              return "";
            }

          } },
        {field: 'status', title: '是否禁用', templet:function (d) {
            if(d.status === 0){
              return "未支付";
            }else if(d.status === 1){
              return "已支付";
            }else if(d.status === 2){
              return "已发货";
            }else if(d.status === 3){
              return "已收货";
            }else if(d.status === 4){
              return "退款";
            }else if(d.status === 5){
              return "退货中";
            }else if(d.status === 6){
              return "已退款";
            }
          }},
        {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
      ]],
    });

    //监听搜索按钮时间
    /*$("#keyword").on("input",function (){
      let name = $(this).val();
      table.reload("currentTableId", {
        page: {
          curr:1
        }
      })
    })*/


    /**
     * 修改
     */

    table.on('tool(currentTableFilter)', function (obj) {
      var data = obj.data;
      if (obj.event === 'edit') {
        sessionStorage.setItem("id",data.id);
        layer.open({
          type:2,
          title:"修改分类信息",
          area:['800px','500px'],
          content:'/order/orderUpdate.html',
          end: function () {
            table.reload("currentTableId")
          }
        })
      }else if(obj.event === 'detail'){
        console.log(data);
        sessionStorage.setItem("id",data.id);
        layer.open({
          type:2,
          title:"订单详情",
          area:['800px','500px'],
          content:'/order/orderDetail.html',
          end: function () {
            table.reload("currentTableId")
          }
        })
      }
    });

  });
</script>
